<?php


namespace app\admin\model\product;

use app\admin\model\BaseModel;
use app\admin\model\product\Loan;

use app\admin\model\user\WechatUser;
/**
 * 管理员管理
 * Class Admin
 * @package app\admin\model
 */
class LoanBrowse extends BaseModel
{
    public static function systemList($where)
    {
        $model = new self;
        $model = $model->alias("l")->join("user u","u.uid=l.uid");
        $model = $model->field("l.*,u.phone");
        if($where['phone'] != "") $model->where("u.phone","like","%$where[phone]%");
        $count = self::counts($model);
        if ($where['page'] && $where['limit']) $model = $model->page((int)$where['page'],(int)$where['limit']);

        $data = $model->select()->each(function ($item) {
            $useinfo = WechatUser::where("uid",$item['uid'])->find()->toArray();
            if (empty($useinfo)) {
                $item['nickname'] = "";
                $item['avatar'] = "";
            }else{
                $item['nickname'] = $useinfo['nickname'];
                $item['avatar'] = $useinfo['avatar'];
            }
            $product = Loan::where("id",$item['loan_id'])->find()->toArray();
            $item['product'] = <<<HTML
            <p><img style="width: 30px;margin-right:10px" src="{$product['image']}"/>{$product['name']}</p>
HTML;
        });
        $data = $data ? $data->toArray() : [];

        return compact("data","count");  
    }


}